// application_data.h
#ifndef APPLICATION_DATA_H
#define APPLICATION_DATA_H

#include <QObject>
#include <QDateTime>
#include <QTimer>

class ApplicationData : public QObject
{
    Q_OBJECT

public:
    ApplicationData() {
        // 定时器
        QTimer *pTimer = new QTimer(this);
        pTimer->setInterval(1000);
        connect(pTimer, &QTimer::timeout, this, &ApplicationData::onTimeout);
        pTimer->start();
    }

    Q_INVOKABLE QDateTime getCurrentDateTime() const {
        return m_dateTime;
    }

signals:
    void dataChanged();

private slots:
    void onTimeout() {
        m_dateTime = QDateTime::currentDateTime();
        emit dataChanged();  // 超时后发射信号
    }

private:
    QDateTime m_dateTime;
};

#endif // APPLICATION_DATA_H
